<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-select v-model="dataForm.shareLevel" placeholder="业绩类型">
          <el-option v-for="item in options" :key="item.val" :label="item.label" :value="item.val"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-select v-model="dataForm.status" placeholder="订单状态">
          <el-option v-for="item in options1" :key="item.val" :label="item.label" :value="item.val"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.transactionId" placeholder="订单号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getDataList()">查询</el-button>
        <!-- <el-button type="primary">返回</el-button> -->
      </el-form-item>
    </el-form>
    <div class="total" style="margin-bottom: 20px;">
      <div>总业绩概览：订单笔数 <span>{{totalVo.orderNum || 0}}笔</span> 销售额 <span>{{totalVo.saleMoney || 0}}元</span> 收益额 <span>{{totalVo.revenueMoney || 0}}元</span> 退款金额 <span>{{totalVo.refundMoney || 0}}元</span> 退款收益额 <span>{{totalVo.refundRevenueMoney || 0}}元</span></div>
    </div>
    <el-table :data="dataList" border v-loading="dataListLoading" style="width: 100%;">
      <el-table-column prop="headimgurl" header-align="center" align="center" label="头像">
        <template slot-scope="scope">
          <img :src="scope.row.headimgurl" style="width: 40px;height: 40px;" />
        </template>
      </el-table-column>
      <el-table-column prop="nickname" header-align="center" align="center" label="昵称"></el-table-column>
      <el-table-column prop="orderNo" header-align="center" align="center" label="订单号"></el-table-column>
      <el-table-column prop="transactionId" header-align="center" align="center" label="交易单号"></el-table-column>
      <el-table-column prop="gmtCreate" header-align="center" align="center" label="订单时间"></el-table-column>
      <el-table-column prop="itemBody" header-align="center" align="center" label="购买项目"></el-table-column>
      <el-table-column prop="orderName" header-align="center" align="center" label="购买页名称"></el-table-column>
      <el-table-column prop="orderAmount" header-align="center" align="center" label="购买价格"></el-table-column>
      <el-table-column prop="refundAmount" header-align="center" align="center" label="退款价格"></el-table-column>
      <el-table-column header-align="center" align="center" label="退款时间">
        <template slot-scope="scope">
          <span>{{scope.row.refundTime || '——'}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="ratio" header-align="center" align="center" label="提成比例"></el-table-column>
      <el-table-column prop="revenue" header-align="center" align="center" label="收益">
        <template slot-scope="scope">
            <span v-if="scope.row.status=='1'">{{scope.row.revenue}}</span>
            <span v-if="scope.row.status=='-1'">0</span>
            <span v-if="scope.row.status=='-2'">{{scope.row.revenue}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="deductRevenue" header-align="center" align="center" label="退款收益额"></el-table-column>
      <el-table-column header-align="center" align="center" label="业绩类型">
        <template slot-scope="scope">
          {{scope.row.shareLevel==1 ?'店铺业绩':''}}
          {{scope.row.shareLevel==2 ?'管理业绩':''}}
          {{scope.row.shareLevel==3 ?'管理业绩':''}}
        </template>
      </el-table-column>
      <el-table-column header-align="center" align="center" label="订单状态">
        <template slot-scope="scope">
          {{scope.row.status==1 ?'已支付':''}}
          {{scope.row.status==-1 ?scope.row.orderType === 1?'退会员':'全部退款':''}}
          {{scope.row.status==-2 ?'部分退款':''}}
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
    <div style="display: flex;justify-content: center;margin: 20px;">
      <el-button type="primary" @click="goBack">返回</el-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      totalVo: {},
      options: [
        {
          val: "1",
          label: "店铺业绩"
        },
        {
          val: "2",
          label: "管理业绩"
        }
      ],
      options1: [
        {
          val: "1",
          label: "已支付"
        },
        {
          val: "-1",
          label: "全部退款"
        },
        {
          val: "-2",
          label: "部分退款"
        }
      ],
      dataForm: {
        key: "",
        rember: "",
        uid: "",
        phone: "",
        nickname: ""
      },
      money:'',//收益
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false
    };
  },
  props: ["id","title"],
  mounted() {
    this.getDataList();
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      let obj = {
        page: this.pageIndex,
        limit: this.pageSize,
        key: this.dataForm.key,
        userId: this.id
      };
      if (this.dataForm.shareLevel) {
        obj.shareLevel = this.dataForm.shareLevel;
      }
      if (this.dataForm.status) {
        obj.status = this.dataForm.status;
      }
      if (this.dataForm.transactionId) {
        obj.transactionId = this.dataForm.transactionId;
      }
      this.$http({
        url: this.$http.adornUrl("/sale/saleRelation/memberGradeOrderList"),
        method: "get",
        params: this.$http.adornParams(obj)
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
          this.dataList.forEach((item,index)=> {
            if (item.status == "-2") {
             item.revenue = item.revenue - item.deductRevenue;
            }
          });
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
      // 总业绩概览
      this.$http({
        url: this.$http.adornUrl("/sale/saleRelation/memberGradeOrderList/statistics"),
        method: "get",
        params: this.$http.adornParams(obj)
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.totalVo = data.res
        }
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    goBack() {
      this.$emit("goback");
    }
  }
};
</script>
<style scoped>
  .total span{
    color: #52b0a3;
    margin-right: 20px;
    font-size: 18px;
  }
</style>
